package com.hdss996.dictationread.ocr;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class JsonParser {
    public static String[] extractWords(String jsonResult) {
        try {
            JSONObject jsonObject = new JSONObject(jsonResult);
            JSONArray wordsArray = jsonObject.getJSONArray("words_result");
            String[] words = new String[wordsArray.length()];
            for (int i = 0; i < wordsArray.length(); i++) {
                JSONObject wordObject = wordsArray.getJSONObject(i);
                words[i] = wordObject.getString("words");
            }
            return words;
        } catch (JSONException e) {
            e.printStackTrace();
            return new String[0];
        }
    }
}
